from rest_framework import serializers
from .models import CourseCategory, Course, Teacher


class CourseCategoryModelSerializer(serializers.ModelSerializer):
    '''课程分类的序列化器'''
    class Meta:
        model = CourseCategory
        fields = ('id', 'name')


class CourseTeacherModelSerializer(serializers.ModelSerializer):
    '''课程所属老师的序列化器'''
    class Meta:
        model = Teacher
        fields = ('name', 'title', 'signature')


class CourseModelSerializer(serializers.ModelSerializer):
    '''课程信息的序列化器'''
    # 这边老师的字段使用了序列化器的嵌套
    teacher = CourseTeacherModelSerializer()    # 1 : 多 老师 : 课程
    # 如果是 有多个老师 需要指定many为True
    # teacher = CourseTeacherModelSerializer(many=True)
    class Meta:
        model = Course
        fields = ('id','name','course_img',"students","lessons","pub_lessons","price","real_price","discount_name","teacher","lesson_list")

# 把上面之前的老师序列化器增加了几个字段
class CourseDetailTeacherSerializer(serializers.ModelSerializer):
    '''课程列表老师信息'''
    class Meta:
        model = Teacher
        fields = ["id","name","role","title","signature","brief","image"]


class CourseDetailModelSerializer(serializers.ModelSerializer):
    '''课程详情信息'''
    teacher = CourseDetailTeacherSerializer()
    class Meta:
        model = Course
        fields = ["id","name","course_img","course_video","students","lessons","pub_lessons","price","teacher","real_brief","level_name","chapter_list","active_time","real_price","discount_name"]


